﻿/********************************************************************************
** 作者： Mick
** 邮箱： zheng_jinfan@126.com
** 主页： http://www.zhengjinfan.cn
** 创始时间：2016-2-5
** 修改人：Mick
** 修改时间：2016-2-29
** 描述：
**      资源库接口
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using BestEasyCMS.Framework.Querying;

namespace BestEasyCMS.Framework.Domain
{
    /// <summary>
    /// 资源库接口
    /// </summary>
    /// <typeparam name="T">实体对象</typeparam>
    /// <typeparam name="TId">主键类型</typeparam>
    public interface IRepository<T, in TId> : IReadOnlyRepository<T, TId> where T : IAggregateRoot
    {
        #region Insert
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="entity">实体对象</param>
        void Insert(T entity);
        /// <summary>
        /// 批量插入数据
        /// </summary>
        /// <param name="pocos">实体集合</param>
        void InsertBulk(IEnumerable<T> pocos);
        #endregion

        #region Update
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="entity">实体对象</param>
        void Update(T entity);
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="poco">实体</param>
        /// <param name="columns">要更新的字段</param>
        /// <returns>受影响行数</returns>
        int Update(T poco, IEnumerable<string> columns);
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <typeparam name="T">实体对象类型</typeparam>
        /// <param name="poco">实体</param>
        /// <param name="fields"></param>
        /// <returns>受影响行数</returns>
        int Update(T poco, Expression<Func<T, object>> fields);
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <typeparam name="T">实体对象类型</typeparam>
        /// <param name="query">查询对象</param>
        /// <returns>受影响行数</returns>
        int Update(Query query);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="whereExpression">lamdba表达式</param>
        /// <returns></returns>
        int UpdateMany(T entity,Expression<Func<T, bool>> whereExpression);
        #endregion

        #region Delete
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="entity">实体对象</param>
        void Delete(T entity);
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="query">查询对象</param>
        /// <returns></returns>
        int Delete(Query query);
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <typeparam name="T">实体对象类型</typeparam>
        /// <param name="pocoOrPrimaryKey">主键</param>
        /// <returns></returns>
        int Delete(TId pocoOrPrimaryKey);
        /// <summary>
        ///  删除数据
        /// </summary>
        /// <param name="whereExpression">lamdba表达式</param>
        /// <returns></returns>
        int DeleteMany(Expression<Func<T, bool>> whereExpression);
        #endregion

        #region Insert Or Update
        /// <summary>
        /// 保存一条记录[插入或更新] 
        /// </summary>
        /// <param name="poco">实体</param>
        void Save(object poco);
        #endregion
    }
}
